<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        table{
            border-collapse: collapse;
            margin: auto auto;
        }
        td{
            width: 150px;
            line-height: 70px;
        }
        .btn{
            width: 150px;
            line-height: 70px;
            font-size: x-large;
        }
        .btn_click{
            width: 302px;
            line-height: 70px;
            font-size: x-large;
        }
        .txt{
            width: 600px;
            line-height: 100px;
            font-size: x-large;text-align: right;
        }
    </style>
</head>
<body>

<table>
    <tr>
        <td colspan="4"><input class="txt" type="text" disabled/></td>
    </tr>
    <tr>
        <td colspan="2"><input class="btn_click" type="button" value="AC"/></td>
        <td colspan="2"><input class="btn_click"  type="button" value="DEL"/></td>
    </tr>
    <tr>
        <td><input class="btn" type="button" value="7"/></td>
        <td><input class="btn" type="button" value="8"/></td>
        <td><input class="btn" type="button" value="9"/></td>
        <td><input class="btn" type="button" value="*"/></td>

    </tr>
    <tr>
        <td><input class="btn" type="button" value="4"/></td>
        <td><input class="btn" type="button" value="5"/></td>
        <td><input class="btn" type="button" value="6"/></td>
        <td><input class="btn" type="button" value="/"/></td>

    </tr>
    <tr>
        <td><input class="btn" type="button" value="1"/></td>
        <td><input class="btn" type="button" value="2"/></td>
        <td><input class="btn" type="button" value="3"/></td>
        <td><input class="btn" type="button" value="-"/></td>

    </tr>
    <tr>
        <td><input class="btn" type="button" value="0"/></td>
        <td><input class="btn" type="button" value="."/></td>
        <td><input class="btn" type="button" value="+"/></td>
        <td><input class="btn" type="button" value="="/></td>

    </tr>

</table>

<script>
    window.onload = function () {
        //定义数组  来接收用户按的数字和计算符号
        var way_res = [];
        //获取按钮对象
        var btn_txt = document.getElementsByClassName("btn");
        //获取屏幕元素
        var txt = document.getElementsByClassName("txt")[0];
        //获取清空按钮和退格按钮
        var btn_way = document.getElementsByClassName("btn_click");
        for (var i = 0; i < btn_way.length; i++) {
            btn_way[i].onclick = function () {
                //判断按钮
                if (this.value == "AC") {
                    way_res = [];
                    txt.value = "";
                }
                else {
                    txt.value = txt.value.substr(0, txt.value.length - 1);
                }
            }
        }
        //给btn_txt  数组对象添加事件
        for (var i = 0; i < btn_txt.length; i++) {
            btn_txt[i].onclick = function () {
                if (txt.value == "" && this.value == ".") {
                    txt.value = "0.";
                }
                else {
                    if (!isNaN(this.value) || this.value == ".") {
                        if (txt.value.indexOf(".") != -1) {
                            if (this.value != ".") {
                                txt.value += this.value;
                            }
                        }
                        else {
                            txt.value += this.value;
                        }
                    }
                    else {
                        if (this.value != "=") {
                            way_res[way_res.length] = txt.value;
                            way_res[way_res.length] = this.value;
                            txt.value = "";
                        }
                        else {
                            way_res[way_res.length] = txt.value;
                            txt.value = eval(way_res.join(""));
                            way_res = [];
                        }
                    }
                }
            }
        }
    }
</script>
</body>
</html>